package com.atguigu.yygh.oss.controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description: TODO
 * @author: 化一帆
 * @date: 2022/12/5 20:40
 * @version: v1.0
 */
@Api
@RestController
@RequestMapping("/admin/oss/file")
public class FileApiController {

    @Autowired
    private FileService fileService;

    /**
     * @description:  上传文件到阿里云oss
     * @author 化一帆
     * @date 2022/12/5 20:41
     */
    @ApiOperation(value = "上传文件接口")
    @PostMapping("fileUpload")
    public R fileUpload(MultipartFile file){
        //阿里云会有一个选择框，需要从本地获取需要上传的文件
        //获取上传文件
        String url=fileService.upload(file);

        return R.ok().message("文件上传成功").data("url",url);
    }
}
